// Package result 状态码
// author likai

package result

// Codes 定义状态
type Codes struct {
	SUCCESS                                 uint
	FAILED                                  uint
	NOAUTH                                  uint
	AUTHFORMATERROR                         uint
	MissingLoginParameter                   uint
	VerificationCodeHasExpired              uint
	CAPTCHANOTTRUE                          uint
	PASSWORDNOTTRUE                         uint
	STATUSISENABLE                          uint
	POSTALREADYEXISTS                       uint
	DEPTISDISTRIBUTE                        uint
	DEPTISEXIST                             uint
	DELSYSMENUFAILED                        uint
	MENUISEXIST                             uint
	ROLENAMEALREADYEXISTS                   uint
	MissingNewAdminParameter                uint
	USERNAMEALREADYEXISTS                   uint
	FILEUPLOADERROR                         uint
	MissingModificationOfPersonalParameters uint
	MissingChangePasswordParameter          uint
	RESETPASSWORD                           uint
	INVALIDTOKEN                            uint
	Message                                 map[uint]string
}

// ApiCode 状态码
var ApiCode = &Codes{
	SUCCESS:                                 200,
	FAILED:                                  501,
	NOAUTH:                                  403,
	AUTHFORMATERROR:                         405,
	MissingLoginParameter:                   407,
	VerificationCodeHasExpired:              408,
	CAPTCHANOTTRUE:                          409,
	PASSWORDNOTTRUE:                         410,
	STATUSISENABLE:                          411,
	POSTALREADYEXISTS:                       417,
	DEPTISDISTRIBUTE:                        416,
	DEPTISEXIST:                             415,
	DELSYSMENUFAILED:                        414,
	MENUISEXIST:                             413,
	ROLENAMEALREADYEXISTS:                   412,
	MissingNewAdminParameter:                418,
	USERNAMEALREADYEXISTS:                   419,
	FILEUPLOADERROR:                         420,
	MissingModificationOfPersonalParameters: 421,
	MissingChangePasswordParameter:          422,
	RESETPASSWORD:                           423,
	INVALIDTOKEN:                            424,
}

// 状态信息
func init() {
	ApiCode.Message = map[uint]string{
		ApiCode.SUCCESS:                                 "成功",
		ApiCode.FAILED:                                  "失败",
		ApiCode.NOAUTH:                                  "请求头中auth为空！",
		ApiCode.AUTHFORMATERROR:                         "请求头中的auth格式错误",
		ApiCode.MissingLoginParameter:                   "缺少登录参数",
		ApiCode.VerificationCodeHasExpired:              "验证码已失效",
		ApiCode.CAPTCHANOTTRUE:                          "验证码错误",
		ApiCode.PASSWORDNOTTRUE:                         "密码错误",
		ApiCode.STATUSISENABLE:                          "账号已被停用，请联系管理员！",
		ApiCode.POSTALREADYEXISTS:                       "岗位名称或岗位编码已存在，请重新输入！",
		ApiCode.DEPTISDISTRIBUTE:                        "部门已分配，无法删除！",
		ApiCode.DEPTISEXIST:                             "部门名称已存在，请重新输入",
		ApiCode.DELSYSMENUFAILED:                        "菜单已分配，不能删除！",
		ApiCode.MENUISEXIST:                             "菜单名称已存在，请重新输入！",
		ApiCode.ROLENAMEALREADYEXISTS:                   "角色名称或者权限字符已存在，请重新输入！",
		ApiCode.MissingNewAdminParameter:                "缺少新增用户参数！",
		ApiCode.USERNAMEALREADYEXISTS:                   "用户名称已存在，请重新输入！",
		ApiCode.FILEUPLOADERROR:                         "文件上传错误！",
		ApiCode.MissingModificationOfPersonalParameters: "缺少修改个人信息参数！",
		ApiCode.MissingChangePasswordParameter:          "缺少修改个人密码参数！",
		ApiCode.RESETPASSWORD:                           "重复密码与新密码不一致！",
		ApiCode.INVALIDTOKEN:                            "无效的token！",
	}
}

// GetMessage 供外部调用
func (c *Codes) GetMessage(code uint) string {
	message, ok := c.Message[code]
	if !ok {
		return ""
	}
	return message
}
